﻿@using System.Collections;
@{

    Layout = null;

    var code = ViewBag.code;
    var type = ViewBag.type;

}
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
@*<link href="~/Content/CommonCss/BootStrap/bootstrap.css" rel="stylesheet" />*@
<link href="~/Content/CommonCss/BootStrap/bootstrap.min.css" rel="stylesheet" />
<style>
    body {
        min-height: 100vh;
        position: relative;
    }

    .triangle-right {
        width: 0;
        height: 0;
        border-top: 5px solid transparent;
        border-left: 10px solid #000000;
        border-bottom: 5px solid transparent;
        display: inline-block;
    }

    .triangle-down {
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 10px solid #000000;
        display: inline-block;
    }

    .box_shadow {
        box-shadow: 0px 0px 20px #888888;
        padding: 20px;
    }

    #T_F {
        height: 150px;
        background: red;
        color: red;
        display: -webkit-flex; /* Safari */
        display: flex;
        justify-content: center;
        align-items: flex-end;
    }

    #T_F_Child {
        width: 110px;
        height: 110px;
        line-height: 110px;
        border-radius: 55px;
        text-align: center;
        font-size: 28px;
        margin-bottom: 10px;
        font-weight: 600;
    }

        #T_F_Child > img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
        }

    .The_P {
        text-indent: 2em;
        margin: 30px 0;
    }

    .The_Box {
        letter-spacing: 7px;
    }

    .fr {
        float: right;
    }

    #QueryLog {
        margin-top: 30px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    #QueryLogUl {
        padding: 0;
        color: #999;
        list-style: none;
    }

    #QueryLogUl>li:nth-child(2n){
        border-bottom: 1px solid #ddd;
        display:flex;
        justify-content:space-between;
    }

    .myTabs.nav-tabs > li.active > a, .myTabs.nav-tabs > li.active > a:focus, .myTabs.nav-tabs > li.active > a:hover {
        color: #555;
        cursor: default;
        background-color: #fff;
        border: 1px solid #ddd;
        border-bottom-color: transparent;
    }

    .space-around {
        display: flex;
        justify-content: space-around;
    }

    .align-content-center {
        display: flex;
        align-content: center;
    }

    #error .glyphicon {
        line-height: 80px;
    }

    .errorBox {
        width: 80px;
        height: 80px;
        border-radius: 50px;
        border: 2px solid #e5e5e5;
        color: #5cb85c;
    }

        .errorBox > div:nth-child(1) {
            height: 35px;
            line-height: 35px;
            text-align: center;
            font-size: 24px;
        }

        .errorBox > div:nth-child(2) {
            text-align: center;
            font-size: 10px;
        }

    .red-500 {
        color: red;
    }

    #error {
        display: none;
    }
</style>

<div role="tabpanel" id="SecurityCode" aria-labelledby="SecurityCode-tab">
    <div id="box" style="padding-bottom:50px;display:none">
        <div id="AntiFakeInfoCon">
            @*头部*@
            <div id="T_F">
                <div id="T_F_Child">
                    <img src="~/Content/CodeSearchImg/error.png" alt="Alternate Text" />
                </div>
            </div>
            @* 对 *@
            <div id="correct" style="padding:0 20px;">
                <p class="The_P" id="corrent_p"></p>
                <div id="success">
                    <div class="box_shadow">
                        <div class="new-row">
                            @*<span>防伪验证码:</span>
                                <span id="The_Code"></span>*@
                        </div>
                        <div class="new-row">
                            <img id="QrCodeImg" style="margin:0 auto;width:70%;display:block" src="~/Content/webImgs/AntiFake/empty.png" />
                        </div>
                        <div class="row">
                            <span style="white-space: nowrap; padding: 0; margin-left: 15px; margin-right: 5px; " class="The_Box col-xs-4 col-sm-4 col-md-4 col-lg-4">企业名称:</span>
                            <span style="word-break: break-all; " id="EnterpriseUse"></span>
                        </div>
                        <div class="row">
                            <span style="white-space: nowrap;padding:0;margin-left: 15px;margin-right:5px; " class="The_Box col-xs-4 col-sm-4 col-md-4 col-lg-4">产品名称:</span>
                                <span style="word-break: break-all; " id="BrandName"></span>
                            </div>
                        <div class="row">
                            <span style="white-space: nowrap;padding:0;margin-left: 15px;margin-right:5px; " class="The_Box col-xs-4 col-sm-4 col-md-4 col-lg-4">查询次数:</span>
                            <span style="word-break: break-all; color:red;font-weight:bolder " id="QueriesNub"></span>
                        </div>
                        <div class="row">
                            <span style="white-space: nowrap; padding: 0; margin-left: 15px; margin-right: 5px; " class="col-xs-4 col-sm-4 col-md-4 col-lg-4">首次查询时间:</span>
                            <span style="word-break: break-all; " id="FirstQueries"></span>
                        </div>
                    </div>
                    <div id="QueryLog" style="clear: both;">
                        <div style="display:flex;align-items:center;">
                            <span style="margin-right:5px;">查询记录</span>
                            <span class="triangle-right fr QueryLogUlBtn"></span>
                        </div>
                    </div>
                    <ul id="QueryLogUl" style="display: none;font-size:12px;">
                        <li>
                            <span id="Count"></span>
                            <span id="Time"></span>
                        </li>
                    </ul>
                </div>
            </div>
            @* 错 *@
            <div id="error">
                <p class="The_P" id="error_p"></p>
               
            </div>
        </div>
    </div>
</div>

<footer style="position:absolute;bottom:20px;color:#999;width:100%;display:flex;justify-content:center;">
    技术支持：码管家云系统 版权所有
</footer>

@*<script src="~/Scripts/jquery.js"></script>*@
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script>

    var Code = '@code'
    var CodeType = '@type'
    var VerCode = "default";

    $(document).ready(function () {
        Search(Code, CodeType);
    });

    function Search(code, codeType) {
        $.ajax({
            url: "/CodeSearch/SearchCreatCode",
            type: "POST",
            dataType: "json",
            data: { Code: code, type: codeType },
            success: function (data) {
             
                if (data.results == "2") {
                    $("#AntiFakeInfoCon").show();
                    $("#success").hide()
                    $("#T_F").css({ "background": "red" })
                    $("#T_F_Child>img").attr("src", "/Content/CodeSearchImg/error.png")
                    $("#error").show();
                    $("#error_p").html(data.res).css({ "text-align": "center" });
                    $("#QueryLog").hide()
                    $("#QueryLogUl").hide()
                    $("#corrent_p").text("尊敬的消费者您好!您查询的产品已实施召回，请联系当地销售商做退回处理！").parent().css('min-height', '420px');

                }

                else if (data.results != "-1") {
                    var the_data = JSON.parse(data.results)


                    if (data.num >= 1 && data.num <= 5) {
                        //正
                        //获取时间
                        function p(s) {
                            return s < 10 ? '0' + s : s;
                        }
                        var myDate = new Date();
                        var year = myDate.getFullYear();
                        var month = myDate.getMonth() + 1;
                        var date = myDate.getDate();
                        var h = myDate.getHours();
                        var m = myDate.getMinutes();
                        var s = myDate.getSeconds();
                        var NowTime = year + '-' + p(month) + "-" + p(date) + " " + p(h) + ':' + p(m) + ":" + p(s);
                        $("#Particulars").show();
                        $("#T_F_Child> img").attr("src", "/Content/CodeSearchImg/right.png");
                        if (the_data[0].EnterpriseUse == "") {
                            $("#EnterpriseUse").html(the_data[0].EnterpriseName)
                        }
                        else {
                            $("#EnterpriseUse").html(the_data[0].EnterpriseUse)
                        }
                        if (the_data[0].ProductName == "") {
                            $("#BrandName").html("产品暂未绑定")
                        } else {
                            $("#BrandName").html(the_data[0].ProductName)
                        }

                        $("#QueriesNub").html(data.num)
                        if (data.num == 1) {
                            $("#FirstQueries").html(NowTime)
                        }
                        else {
                            $("#FirstQueries").html(data.firsttime)
                        }
                        $("#T_F").css({ "background": "green", "color": "green" })
                        if (data.num == 1) {

                            if (the_data[0].Query_Result_Content != "") {
                                $(".The_P").html(the_data[0].Query_Result_Content)
                            }

                            else if (the_data[0].EnterpriseUse == "") {
                               
                                $(".The_P").html('您好！您所查询的是' + the_data[0].EnterpriseName + '生产的品牌产品，是正牌产品的标识，欢迎您再次选购！')
                            }

                        }
                        else if (data.num > 1) {
                            
                            if (the_data[0].EnterpriseName != "") {
                                $(".The_P").text("您所查询的" + the_data[0].EnterpriseName + "产品已于" + data.firsttime + "被首次查询，谨防假冒！");
                            }
                        }

                        Ajax_GetAntiFakeNum(Code)
                    } else {

                        //疑

                        $("#Particulars").show();
                        $("#QueryLog").show();
                        $("#T_F_Child> img").attr("src", "/Content/CodeSearchImg/yi.png");
                      

                        if (the_data[0].EnterpriseUse == "") {
                         

                            $(".The_P").html("您所查询的" + the_data[0].EnterpriseName + "产品已于" + data.firsttime + "被首次查询，谨防假冒！")
                            $("#EnterpriseUse").html(the_data[0].EnterpriseName)
                        }

                        else if (the_data[0].EnterpriseUse != "") {

                            $(".The_P").html("您所查询的" + the_data[0].EnterpriseUse + "产品已于" + data.firsttime + "被首次查询，谨防假冒！")

                            $("#EnterpriseUse").html(the_data[0].EnterpriseUse)
                        }
                        $("#BrandName").html(the_data[0].ProductName)
                        $("#QueriesNub").html(data.num)
                        $("#FirstQueries").html(data.firsttime)
                        $("#T_F").css({ "background": "orange", "color": "orange" })
                        
                        Ajax_GetAntiFakeNum(Code)
                    }

                    if (the_data[0].LabelImage != "") $("#QrCodeImg").attr("src", the_data[0].LabelImage);
                }
                else {
                    //错
                    $("#success").hide()
                    $("#T_F").css({ "background": "red" })
                    $("#T_F_Child>img").attr("src", "/Content/CodeSearchImg/error.png")
                    $("#error").show();
                    $("#error_p").html(data.res).css({ "text-align": "center" });
                    $("#QueryLog").hide()
                    $("#QueryLogUl").hide()
                    if (data.res == "") {
                        $("#corrent_p").text('您所查询的防伪码不存在，防伪码应是不含空格的纯数字编码，请核对，谨防假冒！')
                    } else {
                        $("#corrent_p").text(data.res).parent().css('min-height', '420px');
                    }
                }
                $("#box").show()
            },
            error: function () {
                alert("扫码错")
            }
        })

    }
    function Ajax_GetAntiFakeNum(SeachStr) {
        $.ajax({
            url: ACTION_URL("GetCodeLogDis", "CodeSearch"),
            type: "POST",
            dataType: "json",
            data: {
                Code: SeachStr,
            },
            success: function (response) {
                the_response = JSON.parse(response.info);


                if (response != -1) {
                    $("#QueryLogUl").children().remove();
                    $(".triangle-down").toggleClass("triangle-down").toggleClass("triangle-right")
                    for (var i = 0; i < the_response.length; i++) {
                        if (the_response[i].QueryIp == "::1" && the_response[i].QueryProvince != "") {
                            var $li = "<li><span>" + the_response[i].QueryTime + "</span></li><li><span>第" + (i + 1) + "次查询</span>-<span>" + the_response[i].QueryProvince + "</span></li>"
                        }
                        else if (the_response[i].QueryIp != "::1" && the_response[i].QueryProvince =="") {
                            var $li = "<li><span>" + the_response[i].QueryTime + "</span></li><li><span>第" + (i + 1) + "次查询</span>-<span>" + the_response[i].QueryIp + "</span></li>"
                        }
                        else if (the_response[i].QueryIp == "::1" && the_response[i].QueryProvince == "") {
                            var $li = "<li><span>" + the_response[i].QueryTime + "</span></li><li><span>第" + (i + 1) + "次查询</span></li>"
                        }
                        else{
                            var $li = "<li><span>" + the_response[i].QueryTime + "</span></li><li><span>第" + (i + 1) + "次查询</span>-<span>" + the_response[i].QueryProvince + "</span>-<span>" + the_response[i].QueryIp + "</span></li>"
                        }
                        $("#QueryLogUl").append($li)
                    }
                }
            },
            error: function () {
                alert("历史纪录错")
            }
        });
    }

    $("#QueryLog>div").on("click", function () {
        $("#QueryLogUl").toggle()
        $(".QueryLogUlBtn").toggleClass("triangle-right").toggleClass("triangle-down")
    })

    function ACTION_URL(actionName, controllerName) {
        var _actionUrl = '@Url.Action("ActionName", "ControllerName")';
        return _actionUrl.replace("ActionName", actionName).replace("ControllerName", controllerName);
    }
</script>



